<template>
  <div id="member-head-menu">
    <div class="yh-layout-box">
      <div class="menu-logo cursor" @click="routeToPath('/')">
        <img class="yh-middle" src="@/assets/images/meal/logo.png">
      </div>
      <img class="menu-line" src="@/assets/images/help/help_10.png">
      <div class="menu-title">

        <el-dropdown @command="handleSwitch">
          <span class="el-dropdown-link cursor">
            买家中心<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu class="menu-title-dropdown" slot="dropdown">
            <el-dropdown-item class="cursor" command="seller">切换至卖家中心</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>


      <ul class="menu-list">
        <li :class="ideName == 'memberCenter'?'active':''" @click="routeToPath('/member')">首页</li>
        <li :class="ideName == 'message'?'active':''" @click="routeToPath('/member/message')">消息</li>
      </ul>
      <div class="menu-right">
        <div class="menu-search">
          <div class="search-input">
            <div class="search-select">
              <el-dropdown @command="handleCommand">
                <span class="el-dropdown-link">
                  {{searchActive}}<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="(i, idx) in searchList" :command="i.value" :key="idx">{{ i.label }}</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>

            <input type="text" name="" v-if="searchActive == '商品'" :placeholder="searchList[0].tips" v-model="searchKW" @keyup.enter="submitSearch">
            <input type="text" style="padding-left: 85px" name="" v-else :placeholder="searchList[1].tips" v-model="searchKW" @keyup.enter="submitSearch">

          </div>
          <div class="search-btn" @click="submitSearch">
            <span>搜索</span>
          </div>
        </div>
        <div class="member-menu-cart" @click="routeToPath('/cart/list')">
          <div class="cart-main">
            <span class="icons icons-cart"></span>
            <span class="text">我的进货车</span>
          </div>
          <div class="cart-number">
            {{cartNumber}}
          </div>
        </div>
      </div>

    </div>
  </div>

</template>

<script>
  import { getUserCartNum } from '@/api/cart'
export default {
  props: ['ideName', 'kw'],
  data() {
    return {
      userInfo:this.getUserInfo(),
      cartNumber:0,
      searchList: [{
        label: '商品',
        value: 'goods',
        tips: '请输入商品或品牌名称'
      },{
        label: '云工厂',
        value: 'factory',
        tips: '请输入云工厂名称或品牌名称'
      }],
      searchActive: null,
      searchKW: null,
      menuList: [{
        name: '首页',
        url: '/member/main',
        ide: 'memberCenter'
      },{
        name: '消息',
        url: '/member/message',
        ide: 'message'
      }]
    }
  },
  created() {
    this.searchActive = this.searchList[0].label;
    this.searchKW=this.kw;
    if(this.userInfo){
      this.getUserCartNum()
    }
  },
  methods: {

    // 获取用户购物车数量
    getUserCartNum() {
      getUserCartNum().then(res=>{
        this.cartNumber = res.data;
      })
    },
    handleCommand(e) {
      for (var index in this.searchList) {
        if (this.searchList[index].value == e) {
          this.searchActive = this.searchList[index].label
        }
      }
    },
    handleSwitch() {
      this.routeToOut(this.URL.jumpSeller+'/seller/index')
    },
    submitSearch(){
      if(!this.searchKW && this.searchActive == '商品' && this.pageFrom != 'product') {
        return false;
      }
      if (this.searchActive == '商品') {
        this.routeToOut('/mallplus/search/product?kw=' + this.searchKW)
      } else {
        this.routeToOut('/mallplus/search/shop?factoryName=' + this.searchKW)
      }
    }
  }
}
</script>

<style  lang="scss">
#member-head-menu{
  overflow: hidden;
  background-color: #FFF;
  padding-top: 16px;
  min-width: 1200px;
  padding-bottom: 19px;
  .menu-logo{
    float: left;
  }
  .menu-line{
    margin: 0 20px;
    vertical-align: top;
    float: left;
  }
  .menu-title{
    font-size:20px;
    width:120px;
    float:left;

    // margin-left:20px;
    margin-top:10px;
    // border-left:1px solid #E8E8E8;
    // padding-left:20px;
    height:30px;
    line-height:30px;
    .el-dropdown{
      font-size:20px;
    }
  }
  .menu-list{
    float: left;
    margin-left: 150px;
    li{
      float: left;
      margin-right: 35px;
      font-size: 18px;
      line-height: 50px;
      cursor: pointer;
    }
    .active{
      color: #255B8A;
    }
  }
  .menu-right{
    float: right;
  }
  .menu-search{
    float: left;
    margin-top: 6px;
    position: relative;
    & > div {
      float: left;
    }
    .search-btn{
      cursor: pointer;
      width: 60px;
      height: 40px;
      line-height: 40px;
      margin-right: 20px;
      background-color: #255B8B;
      color: #FFF;
      text-align: center;
    }
    .search-select{
      height: 10px;
      position: absolute;
      line-height: 10px;
      border-radius: 15px 0 0 0;
      padding-left: 20px;
      padding-right: 10px;
      top: 15px;
      left: 4px;
      cursor: pointer;
      .el-dropdown-link{
        font-size: 12px;
      }
    }
    .search-input{
      input{
        background-color: #F0F0F0;
        width: 220px;
        padding: 0 ;
        height: 36px;
        border: 2px solid #255B8B;
        font-size: 12px;
        padding-left: 75px;
      }
      input:focus{
        outline: none;
      }
    }
  }
  .member-menu-cart{
    cursor: pointer;
    width: 160px;
    height: 40px;
    float: left;
    background-color: #F9F9F9;
    border:1px solid #DFDFDF;
    margin-top: 5px;
    .cart-main{
      line-height: 40px;
    }
    .text{
      padding-left: 10px;
    }
    .icons-cart{
      float: left;
      margin-left: 16px;
      margin-top: 12px;
      width: 18px;
      height: 16px;
      background-image: url('../../../assets/images/member/cart.png');
    }
    .cart-number{
      background-color: #255B8A;
      text-align: center;
      color: #fff;
      width: 20px;
      height: 20px;
      line-height: 20px;
      border-radius: 60px;
      margin: 0 auto;
      margin-top: -30px;
      margin-right: 15px;
      float: right;
      font-size: 12px;
    }
  }
}
</style>

<style style="scss">
  .menu-title-dropdown .el-dropdown-menu__item{
    font-size: 16px;
    line-height: 42px;
  }
</style>
